package com.wxapp.common.core.mybatis.mysql;

import com.baomidou.mybatisplus.core.injector.AbstractMethod;
import com.baomidou.mybatisplus.core.metadata.TableInfo;
import com.wxapp.common.constant.enums.SqlMethodEnum;
import org.apache.ibatis.mapping.MappedStatement;
import org.apache.ibatis.mapping.SqlSource;

public class selectFirst extends AbstractMethod {
    private SqlMethodEnum sqlMethod;
    public selectFirst(SqlMethodEnum sqlMethod) {
        super(sqlMethod.getMethod());
        this.sqlMethod=sqlMethod;
    }
    @Override
    public MappedStatement injectMappedStatement(Class<?> mapperClass, Class<?> modelClass, TableInfo tableInfo) {
        SqlSource sqlSource = languageDriver.createSqlSource(configuration, String.format(sqlMethod.getSql(), sqlFirst(), sqlSelectColumns(tableInfo, true), tableInfo.getTableName(), sqlWhereEntityWrapper(true, tableInfo)), modelClass);
        return this.addSelectMappedStatementForTable(mapperClass,  sqlSource, tableInfo);
    }
}